/**
    入驻小区
**/
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            adminProductInfo: {
                products: [],
                total: 0,
                records: 1,
                moreCondition: false,
                productId: '',
                conditions: {
                    categoryId: '',
                    state: '2002',
                    prodName: '',
                    keyword: '',
                    barCode: '',
                    shopId: ''
                },
                productCategorys: []
            }
        },
        _initMethod: function () {
            vc.emit('adminShop', 'initShop', function (_shop) {
                $that.adminProductInfo.conditions.shopId = _shop.shopId;
                $that._listAdminProducts(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            $that._listAdminProducts(DEFAULT_PAGE, DEFAULT_ROWS);
        },
        _initEvent: function () {

            vc.on('adminProduct', 'listProduct', function (_param) {
                $that._listAdminProducts(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            vc.on('pagination', 'page_event', function (_currentPage) {
                $that._listAdminProducts(_currentPage, DEFAULT_ROWS);
            });
        },
        methods: {
            _listAdminProducts: function (_page, _rows) {
                $that.adminProductInfo.conditions.page = _page;
                $that.adminProductInfo.conditions.row = _rows;
                let param = {
                    params: $that.adminProductInfo.conditions
                };

                //发送get请求
                vc.http.apiGet('/product.queryAdminProduct',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        $that.adminProductInfo.total = _json.total;
                        $that.adminProductInfo.records = _json.records;
                        $that.adminProductInfo.products = _json.data;
                        vc.emit('pagination', 'init', {
                            total: $that.adminProductInfo.records,
                            dataCount: $that.adminProductInfo.total,
                            currentPage: _page
                        });
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _listAdminProductsToDay: function () {
                $that.adminProductInfo.conditions.createTime = vc.dateTimeFormat(new Date().getTime());
                $that._listAdminProducts(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            _openDeleteProductModel: function (_product) {
                vc.emit('deleteProduct', 'openDeleteProductModal', _product);
            },
            _queryProductMethod: function () {
                $that._listAdminProducts(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            _viewProductDetail: function (_product) {
                vc.emit('viewQrCode', 'openQrCodeModal', {
                    title: _product.prodName,
                    url: _product.pageUrl,
                    remark: '手机扫码查看商品',
                });
            },
            _moreCondition: function () {
                if ($that.adminProductInfo.moreCondition) {
                    $that.adminProductInfo.moreCondition = false;
                } else {
                    $that.adminProductInfo.moreCondition = true;
                }
            }


        }
    });
})(window.vc);
